﻿@using Covenant.Models.Indicators
@model Indicator
@{
    Layout = "_Layout";
}

<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3">
    <h1 class="h2">Create Indicator</h1>
</div>

<form asp-controller="Indicator" asp-action="CreateFileIndicator">
    <input asp-for="Id" value="@Model.Id" class="form-control" type="hidden">
    <div class="form-row">
        <div class="form-group">
            <label asp-for="Type"></label><br/>
            <select asp-for="Type" asp-items="Html.GetEnumSelectList<IndicatorType>()" class="selectpicker show-menu-arrow" data-dropup-auto="false" data-width="auto"></select>
        </div>
    </div>
    <div id="file-section">
        <div class="form-row">
            <div class="form-group col-md-6">
                <label for="FileName">FileName</label>
                <input id="FileName" name="FileName" class="form-control">
            </div>
            <div class="form-group col-md-6">
                <label for="FilePath">FilePath</label>
                <input id="FilePath" name="FilePath" class="form-control">
            </div>
        </div>
        <div class="form-row">
            <div class="form-group col-md-4">
                <label for="SHA2">SHA2</label>
                <input id="SHA2" name="SHA2" class="form-control">
            </div>
            <div class="form-group col-md-4">
                <label for="SHA1">SHA1</label>
                <input id="SHA1" name="SHA1" class="form-control">
            </div>
            <div class="form-group col-md-4">
                <label for="MD5">MD5</label>
                <input id="MD5" name="MD5" class="form-control">
            </div>
        </div>
    </div>
    <div id="network-section" hidden>
        <div class="form-row">
            <div class="form-group col-md-6">
                <label for="Protocol">Protocol</label>
                <input id="Protocol" name="Protocol" class="form-control" disabled>
            </div>
            <div class="form-group col-md-6">
                <label for="Domain">Domain</label>
                <input id="Domain" name="Domain" class="form-control" disabled>
            </div>
        </div>
        <div class="form-row">
            <div class="form-group col-md-6">
                <label for="IPAddress">IPAddress</label>
                <input id="IPAddress" name="IPAddress" class="form-control" disabled>
            </div>
            <div class="form-group col-md-6">
                <label for="Port">Port</label>
                <input id="Port" name="Port" class="form-control" disabled>
            </div>
        </div>
        <div class="form-row">
            <div class="form-group col-md-6">
                <label for="URI">URI</label>
                <input id="URI" name="URI" class="form-control" disabled>
            </div>
        </div>
    </div>
    <div id="target-section" hidden>
        <div class="form-row">
            <div class="form-group col-md-6">
                <label for="ComputerName">ComputerName</label>
                <input id="ComputerName" name="ComputerName" class="form-control" disabled>
            </div>
            <div class="form-group col-md-6">
                <label for="UserName">UserName</label>
                <input id="UserName" name="UserName" class="form-control" disabled>
            </div>
        </div>
    </div>
    <button type="submit" class="btn btn-primary"><span data-feather="plus"></span> Create</button>
</form>

@section Scripts
{
    <script type="text/javascript">
        $(document).ready(function() {
            function swapType(){
                var type = $(this).children("option:selected").val();
                if (type == 0)
                {
                    $("#file-section").attr("hidden", false);
                    $("#file-section").find("input").prop("disabled", false);

                    $("#network-section").attr("hidden", true);
                    $("#network-section").find("input").prop("disabled", true);

                    $("#target-section").attr("hidden", true);
                    $("#target-section").find("input").prop("disabled", true);

                    $("form").attr("action", "/indicator/createfileindicator");
                }
                else if (type == 1)
                {
                    $("#file-section").attr("hidden", true);
                    $("#file-section").find("input").prop("disabled", true);

                    $("#network-section").attr("hidden", false);
                    $("#network-section").find("input").prop("disabled", false);

                    $("#target-section").attr("hidden", true);
                    $("#target-section").find("input").prop("disabled", true);

                    $("form").attr("action", "/indicator/createnetworkindicator");
                }
                else if (type == 2)
                {
                    $("#file-section").attr("hidden", true);
                    $("#file-section").find("input").prop("disabled", true);

                    $("#network-section").attr("hidden", true);
                    $("#network-section").find("input").prop("disabled", true);

                    $("#target-section").attr("hidden", false);
                    $("#target-section").find("input").prop("disabled", false);

                    $("form").attr("action", "/indicator/createtargetindicator");
                }
            };
            $("#Type").change(swapType);
            swapType();
        });
    </script>
}